# Normal libraries
library(ggplot2)
theme_set(theme_minimal())
library(dplyr)
library(tidyr)
# Libraries for mapping
library(maps)
library(ggmap)
library(RColorBrewer)
library(here)
library(patchwork)
Reading in data
crash <- readr::read_csv('crash2016.csv')
## Parsed with column specification:
## cols(
## .default = col_character(),
## X1 = col_double(),
## REPORT_HEADER_ID = col_double(),
## POSTED_SPEED_LIMIT = col_double(),
## LANE_CNT = col_double(),
## Month = col_double(),
## Day = col_double(),
## Year = col_double(),
## time = col_time(format = ""),
## STREET_NO = col_double(),
## BEAT_OF_OCCURRENCE = col_double(),
## DOORING_I = col_logical(),
## WORKERS_PRESENT_I = col_logical(),
## NUM_UNITS = col_double(),
## INJURIES_TOTAL = col_double(),
## INJURIES_FATAL = col_double(),
## INJURIES_INCAPACITATING = col_double(),
## INJURIES_NON_INCAPACITATING = col_double(),
## INJURIES_REPORTED_NOT_EVIDENT = col_double(),
## INJURIES_NO_INDICATION = col_double(),
## INJURIES_UNKNOWN = col_double()
## # ... with 6 more columns
## )
## See spec(...) for full column specifications.
crash <- crash %>%
mutate(DANGEROUS_TO_DRIVE = (ROADWAY_SURFACE_COND != "DRY"))
crash_with_injury <- crash %>%
filter(INJURIES_TOTAL > 0)
crash_with_injury_winter <- crash_with_injury %>%
filter(Month == 12 | Month < 3)
crash_with_injury_summer <- crash_with_injury %>%
filter(Month < 9 & Month > 5)
Plotting Every Crash
counties <- map_data('county')
chicago_box <- c(left = -87.936287,
bottom = 41.679835,
right = -87.447052,
top = 42.000835)
chicago_map <- get_stamenmap(chicago_box, zoom = 12)
chicago_map %>%
ggmap() +
geom_point(data = crash_with_injury_winter, aes(x=LONGITUDE,y=LATITUDE),size=0.2)

chicago_map %>%
ggmap() +
geom_point(data = crash_with_injury_summer, aes(x=LONGITUDE,y=LATITUDE),size=0.2)

chicago_map %>%
ggmap() +
geom_point(data = crash_with_injury, aes(x=LONGITUDE,y=LATITUDE,color=DANGEROUS_TO_DRIVE),size=0.2)

chicago_map %>%
ggmap() +
geom_point(data = crash_with_injury, aes(x=LONGITUDE,y=LATITUDE),size=0.2) +
geom_density2d(data = crash_with_injury, aes(x=LONGITUDE,y=LATITUDE), size=0.5)
